package com.djnt.catering.database;

import java.util.HashMap;

import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;

public class ViewHotNewsUsers extends HotNews {
	static final String TABLE_NAME = "view_hotnews_users";
	public static final Uri CONTENT_URI = Uri.parse("content://"
			+ CateringProvider.AUTHORITY + "/" + TABLE_NAME);
	private static final String USER_ID = "user_id";
	private static final String LOGO_ID = "logo_id";
	public static HashMap<String, String> PROJECTION_MAP = new HashMap<String, String>();
	static {
		PROJECTION_MAP.put(_ID, _ID);
		PROJECTION_MAP.put(NAME, NAME);
		PROJECTION_MAP.put(BODY, BODY);
		PROJECTION_MAP.put(DATE, DATE);
		PROJECTION_MAP.put(CAPTION, CAPTION);
		PROJECTION_MAP.put(VISIT, VISIT);
		PROJECTION_MAP.put(PHONE, PHONE);
		PROJECTION_MAP.put(EMAIL, EMAIL);
		PROJECTION_MAP.put(STATUS, STATUS);

		PROJECTION_MAP.put(USER_ID, USER_ID);
		PROJECTION_MAP.put(LOGO_ID, LOGO_ID);
		PROJECTION_MAP
				.put(CompanyUsers.COMPANY_NAME, CompanyUsers.COMPANY_NAME);
		PROJECTION_MAP.put(CompanyUsers.COMPANY_ADDRESS,
				CompanyUsers.COMPANY_ADDRESS);
		PROJECTION_MAP.put(CompanyUsers.COMPANY_ZIPCODE,
				CompanyUsers.COMPANY_ZIPCODE);
		PROJECTION_MAP.put(CompanyUsers.COMPANY_HOMEPAGE,
				CompanyUsers.COMPANY_HOMEPAGE);
		PROJECTION_MAP.put(CompanyUsers.COMPANY_PHONE,
				CompanyUsers.COMPANY_PHONE);
		PROJECTION_MAP.put(CompanyUsers.COMPANY_PORTRAITURE,
				CompanyUsers.COMPANY_PORTRAITURE);
		PROJECTION_MAP
				.put(CompanyUsers.CONTACT_NAME, CompanyUsers.CONTACT_NAME);
		PROJECTION_MAP.put(CompanyUsers.CONTACT_PHONE,
				CompanyUsers.CONTACT_PHONE);
		PROJECTION_MAP.put(CompanyUsers.CONTACT_EMAIL,
				CompanyUsers.CONTACT_EMAIL);

		UriMatcherCode.addURI(TABLE_NAME, UriMatcherCode.VIEW_HOTNEWS_USERS);
		UriMatcherCode.addURI(TABLE_NAME + "/#",
				UriMatcherCode.VIEW_HOTNEWS_USERS_ID);
	}

	public static void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL("drop view if exists " + TABLE_NAME + ";");
		db.execSQL("CREATE VIEW " + TABLE_NAME + " AS SELECT " + "A." + _ID
				+ "," + NAME + "," + BODY + "," + DATE + "," + CAPTION + ","
				+ VISIT + "," + PHONE + "," + EMAIL + "," + STATUS + "," + "B."
				+ "_ID" + " AS " + USER_ID + ", B." + LOGO + " AS " + LOGO_ID
				+ "," + CompanyUsers.COMPANY_NAME + ","
				+ CompanyUsers.COMPANY_ADDRESS + ","
				+ CompanyUsers.COMPANY_ZIPCODE + ","
				+ CompanyUsers.COMPANY_HOMEPAGE + ","
				+ CompanyUsers.COMPANY_PHONE + ","
				+ CompanyUsers.COMPANY_PORTRAITURE + ","
				+ CompanyUsers.CONTACT_NAME + "," + CompanyUsers.CONTACT_PHONE
				+ "," + CompanyUsers.CONTACT_EMAIL + " FROM "
				+ HotNews.TABLE_NAME + " as A left outer join "
				+ CompanyUsers.TABLE_NAME + " as B on (B." + CompanyUsers.USER
				+ " = A." + NAME + ");");
	}
}
